package com.chap13;

import com.chap13.LongSum;
import com.chap13.util.Utils;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

/**
 * <p>
 * <code>Test3</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-04-12 11:00
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class Test3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        int processors = Runtime.getRuntime().availableProcessors();
        int[] array = Utils.buildRandomIntArray(100000000);
        LongSum longSum = new LongSum(array, 0, array.length);
        ForkJoinPool forkJoinPool = new ForkJoinPool(processors);
        ForkJoinTask<Long> submit = forkJoinPool.submit(longSum);
        System.out.println(submit.get());
    }
}
